package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.BusinessStatusConstants;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerPageDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author Just、倾城
 * @created 2025-10-17
 * @description
 *
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomerById(@RequestBody Customer customer){
        customer.setUpdateTime(LocalDateTime.now());
        customerService.updateById(customer);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id){
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }
    @PostMapping
    public Result addCustomer(@RequestBody Customer customer){
        customer.setUpdateTime(LocalDateTime.now());
        customer.setCreateTime(LocalDateTime.now());
        customer.setStatus(BusinessStatusConstants.TRANSFER_CUSTOMER);
        customerService.save(customer);
        return Result.success();
    }
    @GetMapping
    public Result list(CustomerPageDTO dto) {
        PageResult<CustomerDO> data =customerService.getList(dto);
        return Result.success(data);
    }
}
